/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ac.man.cs.afzal.tcm.term_similarities;

import ac.man.cs.afzal.tcm.sql_handler.SQL_Handler_Diseases_Impl;
import java.io.*;
import java.util.*;
import java.util.logging.*;

/**
 * Title: Term Classifier

 * @author Hammad Afzal
 * Last Modification Date: 22 Jan, 2013
 * @version 1.0
 */
public class Comparison_Contextual_Diseases_GAD
{

    private String CONTEXT_SIMILARITY_MODE = "CONTEXT_SIMILARITY_MODE";
    private String CONTEXTUAL_COMPARISON_TABLE = "CONTEXTUAL_COMPARISON_TABLE";
    private String database_url = "database_url";
    private String username = "username";
    private String password = "password";


    private boolean operation_mode = false;

    private Vector<String> documents = new Vector();
    private SQL_Handler_Diseases_Impl sqlHandler;

    public Comparison_Contextual_Diseases_GAD()
    {
        Properties props = new Properties();
        try
        {
            props.load(new FileInputStream("Term_Classification.properties"));
            database_url = props.getProperty(database_url);
            username = props.getProperty(username);
            password = props.getProperty(password);

            CONTEXT_SIMILARITY_MODE = props.getProperty(CONTEXT_SIMILARITY_MODE);
            CONTEXTUAL_COMPARISON_TABLE = props.getProperty(CONTEXTUAL_COMPARISON_TABLE);
        }
        catch (FileNotFoundException ex)
        {
            Logger.getLogger(Comparison_Contextual_Diseases_GAD.class.getName()).log(Level.SEVERE, null, ex);
        }
        catch (IOException ex)
        {
            Logger.getLogger(Comparison_Contextual_Diseases_GAD.class.getName()).log(Level.SEVERE, null, ex);
        }

        String[] tables = { CONTEXTUAL_COMPARISON_TABLE};
        sqlHandler = new SQL_Handler_Diseases_Impl();
        sqlHandler.initialize_parameters(database_url, username, password);
        sqlHandler.connect_db();
        sqlHandler.reset_tables(tables);
        
    }

    public void contextual_similarity()
    {
        if (CONTEXT_SIMILARITY_MODE.equals("Nouns"))
        {
            operation_mode = true;
            documents = sqlHandler.get_all_corpus_documents();

            if (documents.isEmpty())
            {
                System.out.println("No Documents are in database");
                System.exit(1);
            }

            sqlHandler.get_all_corpus_terms();
            sqlHandler.get_all_disease_terms();
            sqlHandler.perform_comparison_nouns();
            sqlHandler.close_db();
        }
        else if (CONTEXT_SIMILARITY_MODE.equals("Verbs"))
        {
            operation_mode = true;
            documents = sqlHandler.get_all_corpus_documents();

            if (documents.isEmpty())
            {
                System.out.println("No Documents are in database/file: Me quits");
                System.exit(1);
            }
            sqlHandler.get_all_corpus_terms();
            sqlHandler.get_all_disease_terms();
            sqlHandler.perform_comparison_verbs();
            sqlHandler.close_db();
        }
        else if (CONTEXT_SIMILARITY_MODE.equals("Patterns"))
        {
            operation_mode = true;
            documents = sqlHandler.get_all_corpus_documents();

            if (documents.isEmpty())
            {
                System.out.println("No Documents are in database/file: Me quits");
                System.exit(1);
            }
            sqlHandler.get_all_corpus_terms();
            sqlHandler.get_all_disease_terms();
            sqlHandler.perform_comparison_patterns();

            sqlHandler.close_db();
        }
    }
}
